package com.cash.app.ui.auth

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.cash.app.base.BaseViewModel
import com.cash.app.constant.AppConstant
import com.cash.app.net.NetRequestExecutor
import com.cash.app.net.RetrofitClient
import com.cash.app.ui.auth.api.AuthAPIService
import com.cash.app.ui.auth.model.AuthBankInfoResponse
import com.cash.app.ui.auth.model.AuthTypeRequest
import com.cash.app.ui.auth.model.BindBankRequest
import com.cash.app.ui.auth.model.BindBankResponse

class AuthBankViewModel : BaseViewModel() {

    private val authAPIService by lazy {
        RetrofitClient.createService(AuthAPIService::class.java)
    }

    private val _authBankInfo = MutableLiveData<AuthBankInfoResponse>()
    val authBankInfo: LiveData<AuthBankInfoResponse> = _authBankInfo

    private val _bindBankInfo = MutableLiveData<BindBankResponse>()
    val bindBankInfo: LiveData<BindBankResponse> = _bindBankInfo

    fun getAuthInfoByBank() {
        launchRequest(request = {
            NetRequestExecutor.baseNetRequest {
                authAPIService.getAuthInfoByBank(AuthTypeRequest(authType = AppConstant.AUTH_TYPE_BANK))
            }
        }, onSuccess = { response ->
            response?.let {
                _authBankInfo.value = it
            }
        })
    }

    fun submitBindBank(request: BindBankRequest) {
        launchRequest(request = {
            NetRequestExecutor.baseNetRequest {
                authAPIService.bindBank(request)
            }
        }, onSuccess = { response ->
            response?.let {
                _bindBankInfo.value = it
            }
        })
    }
} 